#!/usr/bin/env php
<?php

/**

title=测试 miscZen::encodeStatistics();
timeout=0
cid=0

- 执行属性data @0000000a00000000000000140000000500000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 执行 @0
- 执行属性data @00000064000000320000000000000000000000000000000000000000000000000000000a0000000500000000000000000000000000000000000000
- 执行属性data @00000005000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004c696e757800382e3100352e3700
- 执行属性data @000000320000001e0000006400000019000000500000000f00000014000000230000000a00000008000000030000000200000001000000005562756e74752032302e303400382e312e3132004d7953514c20382e302e333500

*/

include dirname(__FILE__, 5) . '/test/lib/init.php';

su('admin');

$zen = initReference('misc');
$func = $zen->getMethod('encodeStatistics');

function testEncodeStatistics($statistics = array()) {
    global $zen, $func;
    $instance = $zen->newInstance();
    return $func->invokeArgs($instance, [$statistics]);
}

r(testEncodeStatistics(array('user' => 10, 'task' => 20, 'product' => 5))) && p('data') && e('0000000a00000000000000140000000500000000000000000000000000000000000000000000000000000000000000000000000000000000000000');
r(count(testEncodeStatistics(array()))) && p() && e('0');
r(testEncodeStatistics(array('user' => 100, 'execution' => 50, 'project' => array('scrum' => 10, 'waterfall' => 5)))) && p('data') && e('00000064000000320000000000000000000000000000000000000000000000000000000a0000000500000000000000000000000000000000000000');
r(testEncodeStatistics(array('user' => 5, 'OS' => 'Linux', 'phpversion' => '8.1', 'dbversion' => '5.7'))) && p('data') && e('00000005000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004c696e757800382e3100352e3700');
r(testEncodeStatistics(array('user' => 50, 'execution' => 30, 'task' => 100, 'product' => 25, 'story' => 80, 'doc' => 15, 'bug' => 20, 'case' => 35, 'project' => array('scrum' => 10, 'waterfall' => 8, 'kanban' => 3, 'agileplus' => 2, 'waterfallplus' => 1, 'ipd' => 0), 'OS' => 'Ubuntu 20.04', 'phpversion' => '8.1.12', 'dbversion' => 'MySQL 8.0.35'))) && p('data') && e('000000320000001e0000006400000019000000500000000f00000014000000230000000a00000008000000030000000200000001000000005562756e74752032302e303400382e312e3132004d7953514c20382e302e333500');